package com.ssy.lingxi.marketing.utils;

import cn.hutool.json.JSONUtil;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;

/**
 * @author ds
 * @version 2.0.0
 * @date 2021/5/13
 */
public class FeignLogUtils {

    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(FeignLogUtils.class);

    public static void printLog(String name,Wrapper<?> wrapper){
        if(wrapper!=null&& ResponseCode.SUCCESS.getCode() != wrapper.getCode()){
            log.info(name+"服务调用失败"+JSONUtil.toJsonStr(wrapper));
        }
    }

    public static void printLog(String name,Wrapper<?> wrapper,Object inputParam){
        if(wrapper!=null&& ResponseCode.SUCCESS.getCode() != wrapper.getCode()){
            log.info(name+"服务调用失败:inputParam:{}\r\n response:{}",JSONUtil.toJsonStr(inputParam),JSONUtil.toJsonStr(wrapper));
        }
    }

    public static void printLogBySimpleObj(String name,Wrapper<?> wrapper,Object... inputParam){
        if(wrapper!=null&& ResponseCode.SUCCESS.getCode() != wrapper.getCode()){
            if(inputParam!=null){
                StringBuilder builder=new StringBuilder();
                for(Object obj :inputParam){
                    builder.append("|"+inputParam);
                }
                log.info(name+"服务调用失败:inputParam:{}\r\n response:{}",builder.toString(),JSONUtil.toJsonStr(wrapper));
            }
        }
    }
}
